home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / ODF / OS / FWGraphx / FWIconSh.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  7.7 KB  |  265 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWIconSh.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWICONSH_H
  13. #include "FWIconSh.h"
  14. #endif
  15.  
  16. #ifndef FWGC_H
  17. #include "FWGC.h"
  18. #endif
  19.  
  20. #ifndef SLRENDER_H
  21. #include "SLRender.h"
  22. #endif
  23.  
  24. // ----- Foundation Includes -----
  25.  
  26. #ifndef FWSTREAM_H
  27. #include "FWStream.h"
  28. #endif
  29.  
  30. //========================================================================================
  31. // File scope definitions
  32. //========================================================================================
  33.  
  34. #ifdef FW_BUILD_MAC
  35. #pragma segment FWGraphx_IconShape
  36. #endif
  37.  
  38. //========================================================================================
  39. //    class FW_CIconShape
  40. //========================================================================================
  41.  
  42. FW_DEFINE_AUTO(FW_CIconShape)
  43. FW_DEFINE_CLASS_M1(FW_CIconShape, FW_CBoundedShape)
  44.  
  45. // This class is archivable, but we provide the archiving implementation in a separate
  46. // translation unit in order to enable deadstripping of the archiving-related code
  47. // in parts that do not use archiving with this class.
  48.  
  49. //----------------------------------------------------------------------------------------
  50. //    FW_CIconShape::FW_CIconShape
  51. //----------------------------------------------------------------------------------------
  52.  
  53. FW_CIconShape::FW_CIconShape(const FW_CIcon& Icon,
  54.                              const FW_CRect& rect,
  55.                              FW_RenderIconTransform transform,
  56.                              FW_RenderIconAlignment alignment) :
  57.     FW_CBoundedShape(rect, FW_kFill, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont),
  58.     fIcon(Icon),
  59.     fTransform(transform),
  60.     fAlignment(alignment)
  61. {
  62.     FW_END_CONSTRUCTOR
  63. }
  64.  
  65. //----------------------------------------------------------------------------------------
  66. //    FW_CIconShape::FW_CIconShape
  67. //----------------------------------------------------------------------------------------
  68.  
  69. FW_CIconShape::FW_CIconShape(const FW_CIconShape& other) :
  70.     FW_CBoundedShape(other),
  71.     fIcon(other.fIcon),
  72.     fTransform(other.fTransform),
  73.     fAlignment(other.fAlignment)
  74. {
  75.     FW_END_CONSTRUCTOR
  76. }
  77.  
  78. #if 0
  79. //----------------------------------------------------------------------------------------
  80. //    stream operator >> for FW_RenderIconTransform
  81. //----------------------------------------------------------------------------------------
  82.  
  83. static void operator >>(FW_CReadableStream& stream, FW_RenderIconTransform& transform)
  84. {
  85.     unsigned short temp;
  86.  
  87.     FW_ASSERT(sizeof(FW_RenderIconTransform) <= sizeof(temp));
  88.     
  89.     stream >> temp;
  90.     transform = (FW_RenderIconTransform) temp;
  91. }
  92.  
  93. //----------------------------------------------------------------------------------------
  94. //    stream operator >> for FW_RenderIconTransform
  95. //----------------------------------------------------------------------------------------
  96.  
  97. static void operator <<(FW_CWritableStream& stream, const FW_RenderIconTransform& transform)
  98. {
  99.     unsigned short temp = transform;
  100.  
  101.     FW_ASSERT(sizeof(FW_RenderIconTransform) <= sizeof(temp));
  102.     
  103.     stream << temp;
  104. }
  105.  
  106. #endif
  107.  
  108. //----------------------------------------------------------------------------------------
  109. //    stream operator >> for FW_RenderIconAlignment
  110. //----------------------------------------------------------------------------------------
  111.  
  112. static void operator >>(FW_CReadableStream& stream, FW_RenderIconAlignment& transform)
  113. {
  114.     unsigned short temp;
  115.  
  116.     FW_ASSERT(sizeof(FW_RenderIconAlignment) <= sizeof(temp));
  117.     
  118.     stream >> temp;
  119.     
  120.     transform = (FW_RenderIconAlignment) temp;
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    stream operator << for FW_RenderIconAlignment
  125. //----------------------------------------------------------------------------------------
  126.  
  127. static void operator <<(FW_CWritableStream& stream, const FW_RenderIconAlignment& transform)
  128. {
  129.     unsigned short temp = transform;
  130.  
  131.     FW_ASSERT(sizeof(FW_RenderIconAlignment) <= sizeof(temp));
  132.     
  133.     stream << temp;
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. //    FW_CIconShape::FW_CIconShape
  138. //----------------------------------------------------------------------------------------
  139.  
  140. FW_CIconShape::FW_CIconShape(FW_CReadableStream& stream) :
  141.     FW_CBoundedShape(stream)
  142. {
  143.     stream >> fIcon;
  144.         
  145.     stream >> fTransform;
  146.     
  147.     stream >> fAlignment;
  148.  
  149.     FW_END_CONSTRUCTOR
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. //    FW_CIconShape::~FW_CIconShape
  154. //----------------------------------------------------------------------------------------
  155.  
  156. FW_CIconShape::~FW_CIconShape()
  157. {
  158.     FW_START_DESTRUCTOR
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    FW_CIconShape::operator=
  163. //----------------------------------------------------------------------------------------
  164.  
  165. FW_CIconShape& FW_CIconShape::operator=(const FW_CIconShape& other)
  166. {
  167.     FW_CBoundedShape::operator=(other);
  168.  
  169.     fIcon = other.fIcon;
  170.     fTransform = other.fTransform;
  171.     fAlignment = other.fAlignment;
  172.  
  173.     return *this;
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    FW_CIconShape::Render
  178. //----------------------------------------------------------------------------------------
  179.  
  180. void FW_CIconShape::Render(FW_CGraphicContext& gc) const
  181. {
  182.     FW_PrivRenderIcon(gc.GetEnvironment(),
  183.         gc,
  184.         fIcon,
  185.         fRect,
  186.         fTransform,
  187.         fAlignment,
  188.         GetRenderVerb());
  189.     FW_FailOnEvError(gc.GetEnvironment());
  190. }
  191.  
  192.  
  193. //----------------------------------------------------------------------------------------
  194. //    FW_CIconShape::Copy
  195. //----------------------------------------------------------------------------------------
  196.  
  197. FW_CShape* FW_CIconShape::Copy() const
  198. {
  199.     return FW_NEW(FW_CIconShape, (*this));
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    FW_CIconShape::Flatten
  204. //----------------------------------------------------------------------------------------
  205.  
  206. void FW_CIconShape::Flatten(FW_CWritableStream& stream) const
  207. {
  208.     FW_CBoundedShape::Flatten(stream);
  209.     
  210.     stream << fIcon;
  211.     stream << fTransform;
  212.     stream << fAlignment;
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    FW_CIconShape::RenderIcon
  217. //----------------------------------------------------------------------------------------
  218.  
  219. void FW_CIconShape::RenderIcon(FW_CGraphicContext& gc,
  220.                                const FW_CIcon& icon,
  221.                                const FW_CRect& rect,
  222.                                FW_RenderIconTransform transform,
  223.                                FW_RenderIconAlignment alignment)
  224. {
  225.     FW_PrivRenderIcon(gc.GetEnvironment(),
  226.         gc,
  227.         icon,
  228.         rect,
  229.         transform,
  230.         alignment,
  231.         FW_kFill);
  232.     FW_FailOnEvError(gc.GetEnvironment());
  233. }
  234.  
  235. //----------------------------------------------------------------------------------------
  236. //    FW_CIconShape::GetGeometry
  237. //----------------------------------------------------------------------------------------
  238.  
  239. void FW_CIconShape::GetGeometry(FW_CIcon& icon,
  240.                                 FW_CRect& bounds,
  241.                                 FW_RenderIconTransform& transform,
  242.                                 FW_RenderIconAlignment& alignment) const
  243. {
  244.     icon = fIcon;
  245.     transform = fTransform;
  246.     alignment = fAlignment;
  247.     bounds = fRect;
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    FW_CIconShape::SetGeometry
  252. //----------------------------------------------------------------------------------------
  253.  
  254. void FW_CIconShape::SetGeometry(const FW_CIcon& icon,
  255.                                 const FW_CRect& bounds,
  256.                                 FW_RenderIconTransform transform,
  257.                                 FW_RenderIconAlignment alignment)
  258. {
  259.     fIcon = icon;
  260.     fTransform = transform;
  261.     fAlignment = alignment;
  262.     fRect = bounds;
  263. }
  264.  
  265.